home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
CLGRAPH1.ZIP
/
CL_GRAPH.H
next >
Wrap
C/C++ Source or Header
|
1993-09-02
|
18KB
|
511 lines
#ifndef _2D_H
#define _2D_H
#if defined(__DLL__)
# define _EXPORT _export
#else
# define _EXPORT _CLASSTYPE
#endif
extern "C" {
#include "windows.h"
}
#include <stddef.h>
#include <string.h>
#include <math.h>
#include "cl_list.cpp"
#define MEM_ERROR "Unable to Allocate Memory"
#define NAME_SIZE 20
#define WIN_TITLE_SIZE 100
#define WIN_PTR1 "Clumsy_Ptr1"
#define WIN_PTR2 "Clumsy_Ptr2"
#define BLACK RGB( 0, 0, 0 ) // color black
#define WHITE RGB( 0xFF, 0xFF, 0xFF ) // color white
#define RED RGB( 0xFF, 0, 0 ) // color red
#define GREEN RGB( 0, 0xFF, 0 ) // color green
#define BLUE RGB( 0, 0, 0xFF ) // color blue
extern const HBRUSH NO_BRUSH; // null brush
extern HANDLE hInst;
extern HANDLE hPrevInst;
extern int cmdShow;
extern LPSTR cmdLine;
extern void * operator new(size_t size);
extern void operator delete(void * obj);
LRESULT CALLBACK _export WinProc( HWND hWnd, UINT iMessage,
WPARAM wParam, LPARAM lParam );
typedef char boolean;
// window object class
class _EXPORT WinObj
{
public:
// display a message with a stop icon
virtual
void Error( LPSTR str );
// Display a message with an exclamation icon
virtual
void Warning( LPSTR str );
// Display a message box
virtual
int Message( UINT type, LPSTR str );
};
// class with a cleanup flag
// this class is inherited by any class that needs a flag to check for
// a cleanup before an object fo that class is destroyed.
class _EXPORT CleanUpCheck
{
protected:
boolean cleanUpFlag;
public:
CleanUpCheck() { cleanUpFlag = FALSE; }
void CleanUp( boolean cleanFlag=TRUE ) { cleanUpFlag = cleanFlag; }
};
// class for defining coordinates of a point in space
// space is 2-dimentional in this version
class _EXPORT Coord
{
public:
float x, y;
Coord(); // default constructor initializes x = y = 0
Coord( float xCoor, float yCoor );
Coord operator+( Coord& p ); // return(this + p)
Coord operator-(); // return(-this)
Coord operator-( Coord& p ); // return(this - p)
Coord operator*( Coord& p ); // return(this * p)
Coord Rot( float angle, Coord& p ); // return(this rotated
// by angle around p)
Coord& operator+=( Coord& p ); // this += p
Coord& operator-=( Coord& p ); // this -= p
Coord& operator*=( Coord& p ); // this *= p
Coord& RotBy( float angle, Coord& p ); // rotate this by angle
// around p
};
// Center is a global coordinate point representing (0,0)
extern Coord Center;
// abstract class for all graphic objects
class _EXPORT VisualObject : public WinObj
{
public:
virtual ~VisualObject() {}; // virtual destructor
// definition of virtual methods that apply to all graphic objects
virtual
void Translate( Coord& transValue ) = 0;
virtual
void Rotate( float angle, Coord& center = Center ) = 0;
virtual
void Scale( Coord& scale, Coord& center = Center) = 0;
virtual
void Draw( HDC dc, float angle = 0 ) = 0;
};
// define GraphicList as a linked list of visual object references
typedef LinkedList<VisualObject&> GraphicList;
// class for graphic objects consisting of a collection of graphic objects
class _EXPORT ComplexGraphic : public VisualObject, public CleanUpCheck
{
private:
GraphicList container;
public:
virtual ~ComplexGraphic();
void AddObject( VisualObject& vObj ); // adds object
void Translate( Coord& transValue );
void Rotate( float angle, Coord& center = Center );
void Scale( Coord& scale, Coord& center = Center );
void Draw( HDC dc, float angle = 0 );
};
// class for a space system for graphics
class _EXPORT Space : public ComplexGraphic
{
private:
long infinity; // not used in this version
};
// class for storing Windows pens which are used to define the format
// for drawing lines and arcs
class _EXPORT PenObject
{
protected:
LOGPEN lp; // pen information
public:
PenObject( HPEN penValue ); // create the pen from an already
// existing pen
PenObject( COLORREF color ); // create a pen from a color
void SetPen( HPEN penValue ); // changes the pen to a new one
void SetPen( COLORREF color ); // changes the pen to a new color
COLORREF GetColor(); // returns the color of a pen
int GetWidth(); // returns the width of a pen
UINT GetStyle(); // returns the style of a pen
HPEN ActivatePen( HDC dc ); // activates the pen on a device
// context
void DeactivatePen( HDC dc, HPEN originalPen );
// removes the pen from a device
// context
};
// class for storing Windows brushes which are used to define the format
// for filling areas
class _EXPORT BrushObject
{
protected:
LOGBRUSH lb;
public:
BrushObject( HBRUSH brushValue );
BrushObject( COLORREF color );
void SetBrush( HBRUSH brushValue );
void SetBrush( COLORREF color );
COLORREF GetColor();
int GetHatch();
UINT GetStyle();
HBRUSH ActivateBrush( HDC dc );
void DeactivateBrush( HDC dc, HPEN originalBrush );
};
// graphic class for points
class _EXPORT Point : public PenObject, public VisualObject, protected Coord
{
public:
Point( float x, float y, HPEN pen );
Point( float x, float y, COLORREF color=BLACK );
void Translate( Coord& transValue );
void Rotate( float angle, Coord& center = Center );
void Scale( Coord& scale, Coord& center = Center );
void Draw( HDC dc, float angle = 0 );
Coord& GetCoord();
};
// graphic class for lines
class _EXPORT Line : public PenObject, public VisualObject
{
protected:
Coord p1, p2;
public:
Line( Coord& p1, Coord& p2, COLORREF color=BLACK );
Line( Coord& p1, Coord& p2, HPEN pen );
void Translate( Coord& transValue );
void Rotate( float angle, Coord& center = Center );
void Scale( Coord& scale, Coord& center = Center );
void Draw( HDC dc, float angle = 0 );
Coord& GetCoord1();
Coord& GetCoord2();
};
// graphic class for rectangles
class _EXPORT CRectangle : public BrushObject, public Line
{
private:
void Init( float angle );
protected:
Coord p3, p4;
public:
CRectangle( Coord& topLeft, Coord& bottomRight, float angle,
HPEN pen, HBRUSH brush=NO_BRUSH);
CRectangle( Coord& topLeft, Coord& bottomRight, float angle,
HPEN pen, COLORREF brushColor );
CRectangle( Coord& topLeft, Coord& bottomRight, float angle,
COLORREF penColor, HBRUSH brush=NO_BRUSH );
CRectangle( Coord& topLeft, Coord& bottomRight, float angle,
COLORREF penColor, COLORREF brushColor );
void Translate( Coord& transValue );
void Rotate( float angle, Coord& center =